<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>父组件和子组件</title>
</head>
<body>
<div id="app">
  <cpn></cpn>
</div>
<script src="../js/vue.js"></script>
<script>
  // 1、创建第一个组件构造器(子级组件)
  const childComponent = Vue.extend({
    template: `
      <div>
        <h2>这是子级组件</h2>
      </div>
    `
  })
  // 2、创建第二个组件构造器（父级组件）
  const parentComponent = Vue.extend({
    template: `
      <div>
      <h2>这是父级组件</h2>
      <cpn-sub></cpn-sub>
      </div>
    `,
    components: {
      'cpn-sub': childComponent
    }
  })

  // root组件
  const app = new Vue({
    el: '#app',
    data: {},
    components: {
      'cpn': parentComponent
    }
  });
</script>
</body>
</html>
